package com.source.lightfowl.person.service.impl;

import com.source.lightfowl.person.dao.RolePlateDao;
import com.source.lightfowl.person.dao.RoleUrlDao;
import com.source.lightfowl.person.dao.UrlDao;

import com.source.lightfowl.person.entity.Role_Url;
import com.source.lightfowl.person.entity.Url;
import com.source.lightfowl.person.service.UrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@Service
public class UrlServiceImpl implements UrlService {
    @Autowired
    private UrlDao urlDao;
    @Autowired
    private RoleUrlDao roleUrlDao;

    @Autowired
    private RolePlateDao rolePlateDao;

    @Override
    public Url findUrl(String s, String s1) {
        return urlDao.findByPtypeAndBpid(s, s1);
    }

    @Override
    public void saveRoleUrl(Role_Url role_url) {
        roleUrlDao.save(role_url);
    }

    @Override
    public List<Url> findUrlsByRid(String s) {
        return urlDao.findByRid(s);
    }

    @Override
    public List<Url> finAllUrls() {
        return urlDao.findAll();
    }

    @Override
    public void deleteRoleUrl(String rid) {
        roleUrlDao.deleteByRid(rid);
    }

    public List<String> findOprateAuth(String url, String rid) {
        System.out.println(rid);
        List<String> list = new ArrayList<>();
        String bp = urlDao.findBp(url);
        String p = urlDao.findP(url);
        System.out.println(bp);
        System.out.println(p);
        List<String> eids = rolePlateDao.findByPAndBp(p, bp, rid);
        if (eids.size() == 0) {
            return null;
        } else {
            for (String a : eids){
                list.add(a);
                System.out.println(a);

            }

            return list;
        }

    }

}
